package com.wechat.weibo.controller;

import com.wechat.weibo.entity.User;
import com.wechat.weibo.service.FollowService;
import com.wechat.weibo.service.LoginService;
import com.wechat.weibo.service.ShowService;
import com.wechat.weibo.util.ResultMap;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Api
@Controller
public class ShowController {

    @Autowired
    ShowService showService;
    @Autowired
    LoginService loginService;
    @Autowired
    FollowService followService;

//    个人主页
    @ApiOperation(value = "获取用户的粉丝数 关注状态等")
    @GetMapping("/showUser")
    @ResponseBody
    public ResultMap showUser(String selfID,String otherID){
//        if(selfID==null||otherID==null)return ResultMap.wrong();
        User user=showService.showRelation(selfID,otherID);
        if(user==null)return ResultMap.fail(null);
        if(loginService.getUser(selfID)==null)
            return new ResultMap(200,"your havent login",user);
        return ResultMap.success(user);
    }
//    关注页
    @ApiOperation(value = "获取关注列表")
    @GetMapping("/showpick")
    @ResponseBody
    public ResultMap showPick(String selfID,String otherID){
//        System.out.println(selfID+"  "+otherID);
//        if(selfID==null||otherID==null)return ResultMap.wrong();
        if(loginService.getUser(otherID)==null)return ResultMap.wrong();
        if(selfID.equals(otherID)){
            return ResultMap.success(showService.showSelfPick(selfID));
        }else {
            return ResultMap.success(showService.showOtherPick(selfID,otherID));
        }
    }
//    粉丝页
    @ApiOperation(value = "获取粉丝列表")
    @GetMapping("/showfan")
    @ResponseBody
    public ResultMap showFan(String selfID,String otherID){
//        System.out.println(selfID+"  "+otherID);
//        if(selfID==null||otherID==null)return ResultMap.wrong();
        if(loginService.getUser(otherID)==null)return ResultMap.wrong();
        if(selfID.equals(otherID)){
            return ResultMap.success(showService.showSelfFans(selfID));
        }else {
            return ResultMap.success(showService.showOtherFan(selfID,otherID));
        }
    }
}
